<?
require_once("config.php");
$linklogin = '';
$action = getValue('action','str','POST','',2);
if($action == 'execute') {
   $service = getValue('client_id','str','POST','',2);
   $domain = getValue('domain','str','POST','',2);
   $type = getValue('type','int','POST',0);
   $service = trim($service);
   $domain = trim($domain);
   if($type == 0) {
      $linklogin = 'Vui lòng chọn kiểu kết nối';
   }else {
      $db_link = new db_query('SELECT lin_id,lin_link FROM links WHERE lin_title = "'.$service.'" LIMIT 1');
      $link = mysql_fetch_assoc($db_link->result);
      if(isset($link) && $link['lin_link'] == $domain) {
         if($type == 1)
            $continue = $domain.'/wp-content/plugins/sudo-oauth/SudoOauth.php';
         elseif($type == 2)
            $continue = $domain.'/index.php?sudo-login';
         
         $arr = array('service'=>$service,'continue'=>$continue);
         $arr =json_encode($arr);
         $arr = base64_encode($arr);
         $linklogin = 'http://id.sudo.vn/dang-nhap/oauth/general?token='.$arr.'';
      }else {
         $linklogin = 'Tên miền này chưa tồn tại trên hệ thống Sudo ID';
      }
   }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ID Sudo - Lấy link đăng nhập</title>
    <!-- Core CSS - Include with every page -->
   <link href="/home_v2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
   <div style="width: 800px; margin: 20px auto;">
      <form action="" method="post" class="form-horizontal" role="form">
         <div class="form-group">
            <label class="col-sm-2 control-label" for="Client-name">Client name</label>
            <div class="col-sm-10">
               <input type="text" id="Client-name" class="form-control" name="client_id" placeholder="Nhập tên client đã thống nhất với chúng tôi. Ví dụ: example" />
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-2 control-label" for="Client-domain">Client domain</label>
            <div class="col-sm-10">
               <input type="text" id="Client-domain" class="form-control" name="domain" placeholder="Nhập tên tên miền của client. Ví dụ: http://example.com" />
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-2 control-label" for="Client-domain">Kiểu kết nối</label>
            <div class="col-sm-10">
               <select class="form-control" name="type">
                  <option value="0">--Chọn kiểu kết nối --</option>
                  <option value="1">Plugin Wordpress</option>
                  <option value="2">Addon Xenforo</option>
               </select>
            </div>
         </div>
         <div class="form-group">
            <label class="col-sm-2 control-label" >&nbsp;</label>
            <div class="col-sm-10">
               <input type="hidden" name="action" value="execute" />
               <input type="submit" class="btn btn-primary" value="Lấy link" />
            </div>
         </div>
      </form>
      <div style="padding: 20px 0px;">
         <label>Link đăng nhập</label>
         <textarea id="clipxenforo" class="form-control" rows="3" style="word-wrap:break-word;"><?=$linklogin?></textarea>
      </div>
   </div>

</body>
</html>
